import React from "react";
import {Button, Empty, Form, Input, Modal, Upload} from "antd";
import LocalUtil from "@/utils/LocalUtil.ts";
import {IUserInfoDto} from "@/api/Types/ObjInterfaces.ts";

interface Props {
    open: boolean,
    setOpen: (open: boolean) => void,
    data: IUserInfoDto,
    setData: (data: IUserInfoDto) => void
}

const UpdateUserModal: React.FC<Props> = ({open, setOpen, data}) => {
    const inputData = data

    const close = () => {
        setOpen(false)
    }

    const ok = () => {
        console.log(inputData)
        close()
    }

    if (data == null) {
        return (
            <Modal
                open={open}
                onOk={ok}
                onCancel={close}
                closeIcon={null}
            >
                <Empty />
            </Modal>
        )
    }

    return (
        <Modal
            open={open}
            onOk={ok}
            onCancel={close}
            closeIcon={null}
            title={
                <p>{inputData.id}</p>
            }
        >
            <Form
                wrapperCol={{span: 30}}
                labelCol={{span: 5}}
            >
                <Form.Item
                    label="用户名"
                >
                    <Input
                        prefix="用户名"
                        value={inputData.username}
                    />
                </Form.Item>
                <Form.Item
                    label="昵称"
                >
                    <Input
                        prefix="昵称"
                        value={inputData.nickName}
                    />
                </Form.Item>
                <Form.Item
                    label="头像"
                >
                    <Upload accept=".jpg,.jpeg,.png"
                            action='api/img'
                            headers={{
                                Authorization: LocalUtil.getToken()
                            }}
                            maxCount={1}
                    >
                        <Button>上传图片</Button>
                    </Upload>
                </Form.Item>
                <Form.Item
                    label="权限等级"
                >
                    <Input
                        value={data.level}
                    />
                </Form.Item>
            </Form>
        </Modal>
    )
}

export default UpdateUserModal
